package com.manpower.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.manpower.adapter.FileListAdapter;
import com.manpower.data.FileListItemData;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;

public class UnCheckFileActivity extends AnotherBaseActivity {

	private Button mCommiteButton;
	private Button mDeleteButton;
	private ListView mFileList;
	private ArrayList<FileListItemData> mDatas;
	private FileListAdapter mAdapter;
	private final String FILE_NAME = "file_name";
	private final String FILE_CHECK = "file_check";
	private ArrayList<Integer> mFileId = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uncheck_file);
		initiate();
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		return super.onPrepareOptionsMenu(menu);
	}

	private void initiate() {
		// txtTitle.setText(R.string.label_EnRegistration);
		mDatas = new ArrayList<FileListItemData>();
		mAdapter = new FileListAdapter(this, mDatas);
		// txtTitle.setText(R.string.label_uncheck_file);
		mCommiteButton = (Button) findViewById(R.id.commite_button);
		mDeleteButton = (Button) findViewById(R.id.delete_button);
		mCommiteButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mDatas.size() > 0) {
					mFileId = new ArrayList<Integer>();
					for (int i = 0; i < mAdapter.getCount(); i++) {
						if (((FileListItemData) (mAdapter.getItem(i)))
								.ismIsChecked()) {
							mFileId.add(i);
						}
					}
					if (mFileId.size() == 0) {
						CommiteFileDialog dialog = new CommiteFileDialog(
								UnCheckFileActivity.this, R.style.custom_dialog);
						dialog.show();
					}
				} else {
					CommiteFileDialog dialog = new CommiteFileDialog(
							UnCheckFileActivity.this, R.style.custom_dialog);
					dialog.show();
				}
			}
		});
		mDeleteButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ArrayList<FileListItemData> arrListTemp = new ArrayList<FileListItemData>();
				for (int i = 0; i < mDatas.size(); i++)
					if (!mDatas.get(i).ismIsChecked())
						arrListTemp.add(mDatas.get(i));
				mDatas = arrListTemp;
				mAdapter = new FileListAdapter(UnCheckFileActivity.this, mDatas);
				mFileList.setAdapter(mAdapter);
				//mAdapter.notifyDataSetInvalidated();
			}
		});
		mDeleteButton = (Button) findViewById(R.id.delete_button);
		mFileList = (ListView) findViewById(R.id.file_list);

		mFileList.setAdapter(mAdapter);
		mFileList.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

			}
		});
		updateView();
	}

	private void updateView() {
		for (int i = 0; i < 10; i++) {
			FileListItemData data = new FileListItemData();
			data.setmFileName("未提交文件" + i);
			data.setmIsChecked(false);
			mDatas.add(data);
		}
		mAdapter.notifyDataSetChanged();
	}
}
